package lab03.test14;

import com.mysql.cj.api.mysqla.result.Resultset;

import javax.xml.transform.Result;
import java.sql.*;

/**
 * Created by Administrator on 2017/11/30.
 */
public class Test{
    public static void main(String[] args) {
        //3+1
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;
        String sql="select * from t_userinfo";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            try{
               connection=DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                        "root",
                        "123456"
                );
               statement=connection.createStatement();
               resultSet=statement.executeQuery(sql);
               while (resultSet.next()) {
                   System.out.println( resultSet.getString(1)+" "+
                   resultSet.getString(2)+" "+
                   resultSet.getString(3)+" "+
                   resultSet.getString(4));
               }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
